package com.xiaohao.communication.service;

import com.xiaohao.communication.bean.UsersBaseInfo;
import com.xiaohao.communication.bean.WxOpenId;
import com.xiaohao.communication.dao.UserBaseInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersBaseInfoService {

    @Autowired
    UserBaseInfoDao userBaseInfoDao;


    /*
     * 微信用户登录
     * */
    public void wxLogin(WxOpenId wxOpenId) {
        userBaseInfoDao.wxLogin(wxOpenId);
    }


    //用户登录登录
    public Boolean loginUser(UsersBaseInfo usersBaseInfo){
        Boolean a = null;
        String username = usersBaseInfo.getUsername();
        String password = usersBaseInfo.getPassword();
        List<UsersBaseInfo> usersBaseInfos = userBaseInfoDao.loginUser(username);

        UsersBaseInfo user = usersBaseInfos.get(0);
        String pwd = user.getPassword();
        if (password.equals(pwd)){
            a = true;
        }else{
            a = false;
        }
        System.out.println();
        return a;
    }

    //用户注册
    public void registerUser(UsersBaseInfo usersBaseInfo){
        userBaseInfoDao.registerUser(usersBaseInfo);
    }

    /*
    * 查询用户所有信息
    * */
    public UsersBaseInfo getUserInfo(int id){
        List<UsersBaseInfo> userInfo = userBaseInfoDao.getUserInfo(id);
        UsersBaseInfo usersBaseInfo = userInfo.get(0);
        return usersBaseInfo;
    }


    /*
    *  模糊查询用户
    * */
    public List<UsersBaseInfo> getUserInfoByVagueUsername(String username){
        List<UsersBaseInfo> userInfoByVagueUsername = userBaseInfoDao.getUserInfoByVagueUsername(username);
        return userInfoByVagueUsername;
    }


}
